package com.bugbuff.dubbo.server.controller;

import com.bugbuff.dubbo.server.service.TodayBestService;
import com.bugbuff.common.utils.Cache;
import com.bugbuff.common.vo.ErrorResult;
import com.bugbuff.common.pojo.PageResult;
import com.bugbuff.dubbo.server.vo.RecommendUserQueryParam;
import com.bugbuff.dubbo.server.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("tanhua")
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    @GetMapping("todayBest")
    public ResponseEntity<Object> getTodayBest() {

        TodayBest todayBest = todayBestService.getTodayBest();
        if (todayBest != null) {
            return ResponseEntity.ok(todayBest);
        }
        ErrorResult.ErrorResultBuilder result = ErrorResult.builder().errCode("00006").errMessage("查询失败");

        return ResponseEntity.status(500).body(result);
    }

    @GetMapping("recommendation")
    @Cache
    public ResponseEntity<Object> queryRecommendation(RecommendUserQueryParam param) {
        PageResult result = todayBestService.queryRecommendation(param);
        if (result != null) {
            return ResponseEntity.ok(result);
        }
        ErrorResult.ErrorResultBuilder errResult = ErrorResult.builder().errCode("00007").errMessage("推荐列表查询失败");

        return ResponseEntity.status(500).body(errResult);
    }
}
